/**
 * fileName	:	GtdCollection.java
 * 
 * Author	:	Zhu Chongliang
 * 
 * Date		:	2010-09-24 12:55
 */
package com.kingsoft.gtdsys.biz.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.kingsoft.gtdsys.biz.IGtdCollection;
import com.kingsoft.gtdsys.dao.DAOFactory;
import com.kingsoft.gtdsys.dao.IStuffDAO;
import com.kingsoft.gtdsys.entity.Stuff;

class GtdCollection implements IGtdCollection {
	
	public GtdCollection() {
		
	}
	
	@Override
	public ArrayList<Map<String, String>> getAllStuffs() {
		ArrayList<Map<String, String>> resList = new ArrayList<Map<String,String>>();
		
		IStuffDAO iStuffDAO = DAOFactory.getStuffDAO();
		List<Stuff> allStuff = iStuffDAO.findAll();
		
		for (int i = 0; i <allStuff.size(); i++) {
			Stuff stuff = allStuff.get(i);
			Map<String, String> mapStuff = new HashMap<String, String>();
			
			mapStuff.put("Id", String.valueOf(stuff.getId()));
			mapStuff.put("Content", stuff.getContent());
			mapStuff.put("Date", stuff.getDate());
			
			resList.add(mapStuff);
		}
		
		return resList;
	}
	
	@Override
	public Boolean addStuff(String content, String date) {
		Stuff newStuff = new Stuff();
		
		newStuff.setContent(content);
		newStuff.setDate(date);
		
		IStuffDAO iStuffDAO = DAOFactory.getStuffDAO();
		iStuffDAO.insert(newStuff);
		
		return true;
	}
	
	@Override
	public Boolean DelectStuff(int id) {
		IStuffDAO iStuffDAO = DAOFactory.getStuffDAO();
		iStuffDAO.delete(id);
		
		return true;
	}
	
	@Override
	public Boolean DeleteAllStuff() {
		IStuffDAO iStuffDAO = DAOFactory.getStuffDAO();
		iStuffDAO.deleteAll();
		
		return true;
	}
	
	
	@Override
	public Boolean UpdateStuffContent(int id, String newContent, String newDate) {
		Stuff updateStuff = new Stuff();
		
		updateStuff.setId(id);
		updateStuff.setContent(newContent);
		updateStuff.setDate(newDate);
		
		IStuffDAO iStuffDAO = DAOFactory.getStuffDAO();
		iStuffDAO.update(updateStuff);
		
		return true;
	}
}
